package com.yxq.mdt.app.modules.video.adapter;


import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.modules.socialcontact.model.MainSocialContactModel;
import com.yxq.mdt.app.modules.socialcontact.ui.activity.SocialPersonalHomepageAc;
import com.yxq.mdt.app.modules.video.bean.MainVideoBean;
import com.yxq.mdt.app.modules.video.bean.RecommendBannerBean;
import com.yxq.mdt.app.modules.video.bean.RecommendBean;
import com.yxq.mdt.app.modules.video.bean.RecommendListBean;
import com.yxq.mdt.app.net.ApiModel;

import java.util.List;

import static com.blankj.utilcode.util.ActivityUtils.startActivity;

public class RecommendAdapter extends BaseMultiItemQuickAdapter<MainVideoBean, BaseViewHolder> {

    public RecommendAdapter(List<MainVideoBean> data) {
        super(data);
        addItemType(MainVideoBean.MALL_ITEM_TYPE_BANNER, R.layout.recommend_layout_item_banner);
        addItemType(MainVideoBean.MALL_ITEM_TYPE_GRID_MENU, R.layout.layout_item_grid_list);
    }

    @Override
    protected void convert(BaseViewHolder helper, MainVideoBean item) {
        switch (item.getItemType()) {
            case MainVideoBean.MALL_ITEM_TYPE_BANNER://顶部推荐直播间
                ConvenientBanner<RecommendListBean> banner = helper.getView(R.id.banner);
                banner.setPageIndicator(new int[]{R.drawable.shape_banner_selector_unchecked, R.drawable.shape_banner_selector_checked});
                banner.setPages(new CBViewHolderCreator() {
                    @Override
                    public Holder createHolder(View itemView) {
                        return new ImageHolderView(itemView);
                    }

                    @Override
                    public int getLayoutId() {
                        return R.layout.layout_recomment_banner_item;
                    }
                }, ((RecommendBannerBean) item).getBannerListBean());
                banner.startTurning();
                break;
            case MainVideoBean.MALL_ITEM_TYPE_GRID_MENU://下面直播间
                RecyclerView menuView = helper.getView(R.id.recyclerView);
                menuView.setLayoutManager(new GridLayoutManager(mContext, 2));
                RecommendBean recommendBean = ((RecommendBean) item);
                RecommendDataListAdapter adapter = new RecommendDataListAdapter(R.layout.item_recommend_list, recommendBean.getNavIconListBeanList());
                menuView.setAdapter(adapter);
                adapter.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                        Intent intent = new Intent(mContext, SocialPersonalHomepageAc.class);
                        startActivity(intent);
                    }
                });

                break;
            default:
        }
    }

    /**
     * 图片轮转实现
     */
    class ImageHolderView extends Holder<RecommendListBean> {
        private ImageView imageView;

        public ImageHolderView(View itemView) {
            super(itemView);
        }

        @Override
        protected void initView(View itemView) {
            imageView = itemView.findViewById(R.id.comment_banner_image);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        }

        @Override
        public void updateUI(RecommendListBean bean) {

            GlideHelper.setLoadImage(mContext, bean.getPic_url(), 0, imageView);
        }
    }

}
